import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.*;

/**
 * @author Administrator
 */
public class Server {
    public static int count = 0;

    static Map<String,Socket> sockets =new HashMap<>();

    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(9999);
        while (true) {
            Socket s = ss.accept();
            count++;
            sockets.put(count+"",s);
            Thread thread = new Thread(new ServerThread(s, sockets, count));
            ExecutorService es = new ThreadPoolExecutor(5,10,10L, TimeUnit.MILLISECONDS,
                    new LinkedBlockingDeque<Runnable>(10),Executors.defaultThreadFactory(),
                    new ThreadPoolExecutor.DiscardPolicy());
            es.execute(thread);
        }
    }
}
